package appium;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.concurrent.TimeUnit;

/**
 * https://blog.csdn.net/qq_44757034/article/details/128902719
 */
public class AppiumTest {

    private final static String chromedriver = "C:\\Program Files\\Google\\Chrome\\Application\\chromedriver.exe";

    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", chromedriver);
        ChromeDriver chromeDriver = new ChromeDriver();
        // 设置访问地址
        chromeDriver.get("https://www.baidu.com/");
        try {
            Thread.sleep(3000);

            String pageSource = chromeDriver.getPageSource();
            // html代码转Document对象
            Document newsDocument = Jsoup.parse(pageSource);
            // 找到内容元素
            Elements btn = newsDocument.getElementsByClass("bg s_btn");

            WebElement kw = chromeDriver.findElement(By.id("kw"));
            kw.sendKeys("java");
            //在id为su的按钮上点击
            WebElement su = chromeDriver.findElement(By.id("su"));
            su.click();
            try {
                //设置等待
                chromeDriver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
            }catch (Exception e){
                e.printStackTrace();
            }

            // chromeDriver.quit();
        } catch (Exception e) {
            e.printStackTrace();
            chromeDriver.quit();
        }

    }

}
